package gui.lesson04;

import javax.swing.*;
import java.awt.*;

public class Testicon extends JFrame implements Icon {
    private int width;
    private int height;
    public Testicon(){}
    public Testicon(int width, int height) throws HeadlessException {
        this.width = width;
        this.height = height;
    }
    public void initView(){
        Testicon testicon = new Testicon(100, 100);
        //图标放在标签上，也可以放在按钮上
        JLabel label = new JLabel("icontest", testicon, SwingConstants.CENTER);
        Container contentPane = getContentPane();
        contentPane.add(label);
        this.setVisible(true);
        this.setSize(300,300);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
    public static void main(String[] args) {
        new Testicon().initView();
    }
    @Override
    public void paintIcon(Component c, Graphics g, int x, int y) {
        g.fillOval(x,y,width,height);
    }

    @Override
    public int getIconWidth() {
        return this.width;
    }

    @Override
    public int getIconHeight() {
        return this.height;
    }
}
